﻿using NFinalCompiler.SqlModel;
using System;
using System.IO;
using System.Net;
using System.Collections.Generic;
using System.Threading.Tasks;
using NFinal;

//此代码由NFinalCompiler生成。
//http://bbs.nfinal.com
namespace NFinalCompiler.SqlModel.NetStandard
{
    /// <summary>
    /// 模板类
    /// </summary>
    [View("/NFinalCompiler/SqlModel/NetStandard/Bll.cshtml")]
    public class BllRazor : NFinal.View.RazorView<ModelData>
    {
        /// <summary>
        /// 模板类初始化函数
        /// </summary>
        /// <param name="writer">写对象</param>
        /// <param name="Model">数据</param>
        public BllRazor(NFinal.IO.Writer writer, ModelData Model) : base(writer, Model)
        {
        }
        /// <summary>
        /// 输出模板内容
        /// </summary>
        public override void Execute()
        {
            this.ExecuteAsync().Wait();
        }
        /// <summary>
        /// 输出模板内容(异步)
        /// </summary>
        public override async Task ExecuteAsync()
        {
            await writer.WriteAsync("");
            await writer.WriteAsync("using System;\r\nusing System.Collections.Generic;\r\nusing UUPT.Data.Repository.Repository;\r\nusing ");
            await writer.WriteAsync(Model.ModelNameSpace);
            await writer.WriteAsync(".");
            await writer.WriteAsync(Model.DataBaseShortName);
            await writer.WriteAsync(";\r\nnamespace ");
            await writer.WriteAsync(Model.BLLNameSpace);
            await writer.WriteAsync(".");
            await writer.WriteAsync(Model.DataBaseShortName);
            await writer.WriteAsync("\r\n{\r\n    /// <summary>\r\n    /// ");
            await writer.WriteAsync(Model.Table.Description);
            await writer.WriteAsync("BLL\r\n    ///</summary>\r\n    public partial class ");
            await writer.WriteAsync(ModelHelper.GetTableName(Model.Table));
            await writer.WriteAsync("BLL : Repository<");
            await writer.WriteAsync(ModelHelper.GetTableName(Model.Table));
            await writer.WriteAsync("Info>\r\n    {\r\n        private static ");
            await writer.WriteAsync(ModelHelper.GetTableName(Model.Table));
            await writer.WriteAsync("BLL _instance;\r\n        private static readonly object Lock = new object();\r\n        public static ");
            await writer.WriteAsync(ModelHelper.GetTableName(Model.Table));
            await writer.WriteAsync("BLL Instance\r\n        {\r\n            get\r\n            {\r\n                if (_instance == null)\r\n                {\r\n                    lock (Lock)\r\n                    {\r\n                        if (_instance == null)\r\n                        {\r\n                            _instance = new ");
            await writer.WriteAsync(ModelHelper.GetTableName(Model.Table));
            await writer.WriteAsync("BLL();\r\n                        }\r\n                    }\r\n                }\r\n                return _instance;\r\n            }\r\n        }\r\n        public ");
            await writer.WriteAsync(ModelHelper.GetTableName(Model.Table));
            await writer.WriteAsync("BLL() : base(new ");
            await writer.WriteAsync(ModelHelper.GetTableName(Model.Table));
            await writer.WriteAsync("Dal())\r\n        {\r\n        }\r\n\r\n    }\r\n}");
        }
    }
}
